/**
 * author: zhangwei
 * 角色管理列表
 */
userType = '${userType}'
var main = {

    init: function() {
        this.initTable();
        this.tabBind();
    },
    initTable: function() {
        var _this=this;
        loadTable();

    },
    tabBind: function() {
        layui.use(['form'], function () {
            var form = layui.form;
        });
    }
}
main.init();

function loadTable() {
    layui.use(['table','laypage'], function(){
        var table = layui.table;
        var form = layui.form;
        laypage = layui.laypage;
        var page = 1
        var limit = 10
        var url = "/plan/queryAll"
        if (userType == 'student'){
            url = '/plan/queryPlanList'
        }
        $.ajax({
            type:"get",
            async:false,
            url:url,
            success:function(result) {
                if (result.code == property.successCode) {
                    data = result.data
                    laypage.render({
                        elem: 'page'
                        ,count: data.length
                        ,limit: 5
                        ,limits: [5,10, 30, 50]
                        ,jump: function(obj){
                            //模拟渲染
                            document.getElementById('planList').innerHTML = function(){
                                var arr = []
                                    ,thisData = data.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
                                layui.each(thisData, function(index, item){
                                    htmlStr = '<div  class="blogs"><h3 class="blogtitle"><a >'+item.planName+'</a></h3>'
                                    htmlStr = htmlStr+'<div class="bloginfo"><ul><li><label>面向对象:</label><span>'+item.joinPeopleStr+'</span></li>'+
                                    '<li><label>当前状态:</label><span>'+item.statusStr+'</span></li> </ul> </div>'
                                    htmlStr = htmlStr+'<p class="blogtext">'+item.planDesc+'</p>' +
                                        ' <div class="bloginfo"><ul><li><label >开始时间:</label><span >'+formatSimpleDate(item.startTime)+'</span></li>\n' +
                                        '<li><label >截止时间:</label><span >'+formatSimpleDate(item.endTime)+'</span></li>\n' +
                                        '</ul>\n';

                                        htmlStr = htmlStr + '<a class="read-more" data-id="'+item.id+'">查看</a>\n';

                                    htmlStr = htmlStr+ '</div></div>'
                                    arr.push(htmlStr);
                                });
                                return arr.join('');
                            }();
                        }
                    });
                } else{
                    errorMsg(result.msg);
                }
            },
            error:function(result) {
                errorMsg("系统异常");
            }
        });

        $('body').on('click','.read-more',function(){
            id = $(this).attr("data-id")
            localStorage.planId = id
            parent.$t.goToPageSimple("/plan/detailShow",'查看计划详情', "/plan/show");

        })


    });
}

